package com.it.tools;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 羡羡
 *
 * 全局异常
 */
@ControllerAdvice
public class GlobalControllerAdvice {

    /**
     * 普通异常处理
     * @param ex
     * @return
     */
    @ExceptionHandler(NormalException.class)
    public ModelAndView handleNormal(NormalException ex){
        ModelAndView mv=new ModelAndView();
        mv.addObject("errmsg",ex.getMessage());
        mv.setViewName("err500");
        return mv;
    }

    /**
     * ajax异常
     * @param ex
     * @return
     */
    @ExceptionHandler(AjaxException.class)
    @RequestMapping
    public JsonResult handlenAjax(AjaxException ex){
        JsonResult js=new JsonResult(500,ex.getMessage());
        return js;
    }
}
